<?php
	class SchoolModel extends Model {
		function SchoolModel()
		{
			parent::Model();			
		}
		
		function add($data)
		{
			$dataDB = array(
               'school_name' => $data['school_name'] ,
				'school_detail' => $data['school_detail'] ,
			   'create_by' => $this->session->userdata('username'),
			   'is_active' => 1
            );
            $this->db->set('create_date', 'NOW()', FALSE); 
			$this->db->insert('school', $dataDB);
			return $this->db->insert_id();
		}
		
				
		function update($data)
		{			
			$dataDB = array(
              'school_name' => $data['school_name'] ,
			'school_detail' => $data['school_detail'] ,
			   'update_by' => $this->session->userdata('username')
            );
            $this->db->set('update_date', 'NOW()', FALSE); 
            $this->db->where('school_id', $data['school_id']);
			$this->db->update('school', $dataDB); 
		}
		
		
		function getAll()
		{
			$this->db->order_by("school_name", "asc"); 
			$query = $this->db->get_where('school', array('is_active' => 1));
			return $query->result();
		}
		
		function getByID($id)
		{
			$query = $this->db->get_where('school', array('school_id' => $id, 'is_active' => 1));
			return $query->row_array();
		}
		
		function getByNameLike($key)
		{
			$this->db->like('school_name', $key); 
			$this->db->order_by("school_name", "asc"); 
			$query = $this->db->get_where('school', array('is_active' => 1));
			return $query->result();
		}
		
		function delete($newsID)
		{
			$data = array(
               'is_active' => 0,
			   'update_by' => $this->session->userdata('username')   
            );
            $this->db->set('update_date', 'NOW()', FALSE); 
            $this->db->where('school_id', $newsID);
			$this->db->update('school', $data); 
		}
	}
?>